package com.mengxuegu.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;

@Configuration
@EnableWebFluxSecurity
public class WebSecurityConfig {

    @Bean
    public SecurityWebFilterChain securityFilterChain(ServerHttpSecurity httpSecurity) {
        httpSecurity.csrf().disable().authorizeExchange()
                .pathMatchers("/swagger-ui.html","/doc.html").permitAll()
                .pathMatchers("/swagger-resources/**","/webjars/**","/*/api-docs").permitAll()
                .pathMatchers(HttpMethod.POST).permitAll()
                .pathMatchers(HttpMethod.GET).permitAll()
                .and()
                .formLogin();
        return httpSecurity.build();
    }
}